package net.butfly.bus.client.connection;

import net.butfly.bus.config.bean.NodeBean;
import net.butfly.bus.config.detail.ConnectionConfig;
import net.butfly.bus.config.detail.HessianConnectionConfig;
import net.butfly.bus.impl.Connection;

public class ConnectionFactory {
	@Deprecated
	public enum Type {
		hessian, local;
		public static Type parse(String type) {
			return Type.valueOf(type.toLowerCase());
		}

		public Object getPrototype() {
			switch (this) {
			case hessian:
				return new HessianConnectionConfig();
			default:
				return null;
			}
		}
	}

	public static Connection getConnection(NodeBean nodeBean) {
		Class<? extends Connection> clazz = nodeBean.getConnection().getType();
		if (HessianConnection.class.equals(clazz)) {
			HessianConnectionConfig config = (HessianConnectionConfig) nodeBean.getConnection().getConfig();
			HessianConnection conn = new HessianConnection(config.getPath(), config.getTimeout() != null ? Long.valueOf(config
					.getTimeout()) : 0, null);
			return conn;
		}
		return null;
	}

	public static ConnectionConfig getConfig(Class<? extends Connection> connectionClass) {
		if (HessianConnection.class.equals(connectionClass))
			return new HessianConnectionConfig();
		return null;
	}
}
